home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 5 code / Lisp Mini-App / Program / mini-app-example.lisp < prev    next >
Encoding:
Text File  |  1992-04-08  |  5.2 KB  |  145 lines  |  [TEXT/CCL2]

  1. #|
  2.    mini-app-example.lisp
  3.  
  4.    An example of how the Mini-Application core technology can be
  5.    used to build a simple application.
  6.  
  7.    To run the Mini-Application, see "build-and-run-mini-app.lisp".
  8.  
  9.    This file is loaded on top of the Mini-Application core technology
  10.    upon which it defines the items to be instantiated in the tool
  11.    palette (their class, name, and visible representation), and their
  12.    behavior when they are selected. The core technology already knows
  13.    about draw-items.
  14.  
  15.    For further info, see files "About Mini-App" and "Instructions".
  16.  
  17.  
  18.    Copyright 1990, 1991 by Ruben Kleiman for Apple Computer, Inc.
  19.    Acknowledgements: Thanks to Dave Vronay for some pieces of code.
  20.  
  21.    Change History.
  22.    03-11-92 slm  Changed all occurrences of defvar to defparameter (8)
  23.                  so that after the Mini-Application is modified, the 
  24.                  changed files can be re-evaluated immediately.
  25.    03-09-92 slm  Updated file header comments.
  26.    03-07-92 slm  Adapted from superseded file "example.lisp".
  27.  
  28. |#
  29.  
  30. ;;; ________________________________________________________________________________________
  31. ;;; SOME DRAW-ITEM PROTOTYPES
  32. ;;;
  33.  
  34. ;;; We create a round button, a check box, a radio button, a text field, a
  35. ;;; QuickDraw rectangle and oval.  We will put them up on a palette.
  36. ;;;
  37.  
  38. (defparameter *round-button* (create-draw-item :name "Round Button" 
  39.                                                :class 'round-button))
  40.  
  41. (defparameter *check-box* (create-draw-item :name "Check Box"
  42.                                             :class 'check-box))
  43.  
  44. (defparameter *radio-button* (create-draw-item :name "Radio Button" 
  45.                                                :class 'radio-button))
  46.  
  47. (defparameter *text* (create-draw-item :name "Text"
  48.                                        :class 'text))
  49.  
  50. (defparameter *rectangle* (create-draw-item :name "Rectangle"
  51.                                             :class 'rectangle))
  52.  
  53. (defparameter *oval* (create-draw-item :name "Oval"
  54.                                        :class 'oval))
  55.  
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57. ;;; mouse-down [draw-item]
  58. ;;;
  59. ;;;   Here, we over-ride the default mouse-down method for draw-item
  60. ;;;   to set the global *clonable-item* to the name of the class
  61. ;;;   of the draw-item which has been selected.  This will let the
  62. ;;;   windows know which object to create on a window when the user
  63. ;;;   uses the select rectangle style.
  64. ;;;
  65. (defmethod mouse-down ((me draw-item) where)
  66.   (declare (ignore where))
  67.   (setq *clonable-item* me))
  68.  
  69.  
  70. ;;; ________________________________________________________________________________________
  71. ;;; SOME TOOL PROTOTYPES
  72. ;;;
  73.  
  74. ;;; We create three icons that will stand for palette tools.
  75.  
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77. ;;; *browse-tool*
  78. ;;;
  79. ;;;   This tool will be used to set windows into browse mode.
  80. ;;;
  81. (defclass browser-tool (icon-draw-item)
  82.   ()
  83.   )
  84.  
  85. (defparameter *browse-tool* (create-tool :name "Browse"
  86.                                          :class 'browser-tool
  87.                                          :resource-id 102))
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ;;; mouse-down [browser-tool]
  91. ;;;
  92. ;;;   This mouse-down handler will switch the author/browse mode
  93. ;;;   of all draw-dialog windows and put a dialog box
  94. ;;;   showing what mode we are now in.
  95. ;;;
  96. (defmethod mouse-down ((browser browser-tool) where)
  97.   (declare (ignore where))
  98.   (setq *clonable-item* nil)    ; Disable creation via rectangle selection
  99.   (let ((browse-mode nil))      ; Peek at current browse mode
  100.     (dolist (window (windows :class 'draw-dialog))
  101.       (and (neq (type-of window) 'PALETTE)
  102.            (setq browse-mode
  103.                  (setf (slot-value window 'browse-mode)
  104.                        (not (slot-value window 'browse-mode))))))
  105.     ;(ed-beep)
  106.     (message-dialog (format 
  107.                      nil 
  108.                      "~%All drawing windows are now in ~:[author~;browse~] mode" 
  109.                      browse-mode))))
  110.  
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112. ;;; *quit-tool*
  113. ;;;
  114. ;;;     This tool can be used to quit the mini-application.
  115. ;;;
  116. (defclass quit-tool (icon-draw-item)
  117.   ()
  118.   )
  119.  
  120. (defparameter *quit-tool* (create-tool :name "Quit"
  121.                                        :class 'quit-tool
  122.                                        :resource-id 103))
  123.  
  124. (defmethod mouse-down ((me quit-tool) where)
  125.   (declare (ignore where))
  126.   (when (y-or-n-dialog "Are you sure you want to Quit our wonderful application?")
  127.     (quit)))   ;Quits MCL too
  128.  
  129. ;;; ________________________________________________________________________________________
  130. ;;; LIST OF AVAILABLE TOOL AND DRAW-ITEM PROTOTYPES
  131. ;;;
  132.  
  133. (setq *available-tools* (list *browse-tool*
  134.                               *quit-tool*))
  135.  
  136. (setq *available-draw-items* (list *round-button*
  137.                                    *radio-button*
  138.                                    *check-box*
  139.                                    *text*
  140.                                    *oval*
  141.                                    *rectangle*))
  142.  
  143. ;end of file mini-app-example.lisp
  144. ;------------------------------------------------
  145.